
import java.io.IOException;
import java.nio.channels.ServerSocketChannel;

import nio.engine.AcceptCallback;
import nio.engine.NioEngine;
import nio.engine.NioServer;

public class NioServerImplementation extends NioServer{

	private ServerSocketChannel serverSocketChannel;
	private AcceptCallback acceptCallback;

	public NioServerImplementation(ServerSocketChannel serverSocketChannel, AcceptCallback acceptCallback) {
		this.serverSocketChannel = serverSocketChannel;
		this.acceptCallback = acceptCallback;
	}

	public AcceptCallback getAcceptCallback(){
		return this.acceptCallback;
	}
	
	@Override
	public void close() {
		try {
			serverSocketChannel.close();
		} catch (IOException e) {
			NioEngine.panic("Error while closing NioServer");
		}
	}

	@Override
	public int getPort() {
		return serverSocketChannel.socket().getLocalPort();
	}

}

